home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / sossnt.zip / SOSSNT / RPC / SVC_AUNX.C < prev    next >
C/C++ Source or Header  |  1993-03-06  |  4KB  |  151 lines

  1. /*
  2.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  3.  * unrestricted use provided that this legend is included on all tape
  4.  * media and as a part of the software program in whole or part.  Users
  5.  * may copy or modify Sun RPC without charge, but are not authorized
  6.  * to license or distribute it to anyone else except as part of a product or
  7.  * program developed by the user.
  8.  * 
  9.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12.  * 
  13.  * Sun RPC is provided with no support and without any obligation on the
  14.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  15.  * modification or enhancement.
  16.  * 
  17.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19.  * OR ANY PART THEREOF.
  20.  * 
  21.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22.  * or profits or other special, indirect and consequential damages, even if
  23.  * Sun has been advised of the possibility of such damages.
  24.  * 
  25.  * Sun Microsystems, Inc.
  26.  * 2550 Garcia Avenue
  27.  * Mountain View, California  94043
  28.  */
  29. #ifndef lint
  30. static char sccsid[] = "@(#)svc_auth_unix.c 1.1 86/02/03 Copyr 1984 Sun Micro";
  31. #endif
  32.  
  33. /*
  34.  * svc_auth_unix.c
  35.  * Handles UNIX flavor authentication parameters on the service side of rpc.
  36.  * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
  37.  * _svcauth_unix does full blown unix style uid,gid+gids auth,
  38.  * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
  39.  * Note: the shorthand has been gutted for efficiency.
  40.  *
  41.  * Copyright (C) 1984, Sun Microsystems, Inc.
  42.  */
  43.  
  44. #include <stdio.h>
  45. #include <winsock.h>
  46. #include "bcopy.h"
  47. #include "types.h"
  48. /* #include <sys/time.h> */
  49. /* #include "in.h" */
  50. #include "xdr.h"
  51. #include "auth.h"
  52. #include "clnt.h"
  53. #include "rpc_msg.h"
  54. #include "svc.h"
  55. #include "a_unix.h"
  56. #include "svc_auth.h"
  57. #include <dos.h>
  58.  
  59. #define    RNDUP(x)  ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
  60.            * BYTES_PER_XDR_UNIT)
  61.  
  62. /*
  63.  * Unix longhand authenticator
  64.  */
  65. enum auth_stat
  66. _svcauth_unix(rqst, msg)
  67.     struct svc_req *rqst;
  68.     struct rpc_msg *msg;
  69. {
  70.     enum auth_stat stat;
  71.     XDR xdrs;
  72. #ifdef OLDSTUFF
  73.     struct SREGS sr;
  74. #endif
  75.     struct authunix_parms *aup;
  76.     long *buf;
  77.     struct area {
  78.         struct authunix_parms area_aup;
  79.         char area_machname[MAX_MACHINE_NAME];
  80.         int area_gids[NGRPS];
  81.     } *area;
  82.     u_int auth_len;
  83.     int str_len, gid_len;
  84.     int i;
  85.  
  86.     area = (struct area *) rqst->rq_clntcred;
  87.     aup = &area->area_aup;
  88.     aup->aup_machname = area->area_machname;
  89.     aup->aup_gids = area->area_gids;
  90.     auth_len = (u_int)msg->rm_call.cb_cred.oa_length;
  91. #ifdef OLDSTUFF
  92.     segread(&sr);
  93. #endif
  94.     xdrmem_create(&xdrs, (char *) msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
  95.     buf = XDR_INLINE(&xdrs, auth_len);
  96.     if (buf != NULL) {
  97.         aup->aup_time = IXDR_GET_LONG(buf);
  98.         str_len = IXDR_GET_U_LONG(buf);
  99.         bcopy_fn((char*)buf, (char*)(aup->aup_machname), str_len);
  100.         aup->aup_machname[str_len] = 0;
  101.         str_len = RNDUP(str_len);
  102.         buf += str_len / sizeof (long);
  103.         aup->aup_uid = IXDR_GET_LONG(buf);
  104.         aup->aup_gid = IXDR_GET_LONG(buf);
  105.         gid_len = IXDR_GET_U_LONG(buf);
  106.         if (gid_len > NGRPS) {
  107.             stat = AUTH_BADCRED;
  108.             goto done;
  109.         }
  110.         aup->aup_len = gid_len;
  111.         for (i = 0; i < gid_len; i++) {
  112.             aup->aup_gids[i] = IXDR_GET_LONG(buf);
  113.         }
  114.         /*
  115.          * five is the smallest unix credentials structure -
  116.          * timestamp, hostname len (0), uid, gid, and gids len (0).
  117.          */
  118.         if ((unsigned)((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len) > auth_len) {
  119.             printf("bad auth_len gid %d str %d auth %d\n",
  120.                    gid_len, auth_len, auth_len);
  121.             stat = AUTH_BADCRED;
  122.             goto done;
  123.         }
  124.     } else if (! xdr_authunix_parms(&xdrs, aup)) {
  125.         xdrs.x_op = XDR_FREE;
  126.         (void)xdr_authunix_parms(&xdrs, aup);
  127.         stat = AUTH_BADCRED;
  128.         goto done;
  129.     }
  130.     rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
  131.     rqst->rq_xprt->xp_verf.oa_length = 0;
  132.     stat = AUTH_OK;
  133. done:
  134.     XDR_DESTROY(&xdrs);
  135.     return (stat);
  136. }
  137.  
  138.  
  139. /*
  140.  * Shorthand unix authenticator
  141.  * Looks up longhand in a cache.
  142.  */
  143. /*ARGSUSED*/
  144. enum auth_stat 
  145. _svcauth_short(rqst, msg)
  146.     struct svc_req *rqst;
  147.     struct rpc_msg *msg;
  148. {
  149.     return (AUTH_REJECTEDCRED);
  150. }
  151.